package com.zrwl.poscloud.core.restapi.admin.baseInfo;


import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.Delete;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.commons.validator.group.Update;
import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.xo.service.UserAdminRService;
import com.zrwl.poscloud.xo.vo.UserAdminRVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户管理员关联表 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2021-06-01
 */
@RestController
@Api(value = "用户管理员关联表相关接口", tags = {"用户管理员关联表相关接口"})
@RequestMapping("/userAdminR")
@Slf4j
public class UserAdminRRestApi {
    @Autowired
    private UserAdminRService userAdminRService;

    @AuthorityVerify
    @ApiOperation(value = "获取用户管理员关联表列表", notes = "获取用户管理员关联表列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody UserAdminRVO userAdminRVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取用户管理员关联表列表: {}", userAdminRVO);
        return ResultUtil.successWithData(userAdminRService.getPageList(userAdminRVO));
    }
    @AuthorityVerify
    @OperationLogger(value = "新增用户管理员关联表")    @ApiOperation(value = "新增用户管理员关联表", notes = "新增用户管理员关联表", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody UserAdminRVO userAdminRVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("新增用户管理员关联表: {}", userAdminRVO);
        return userAdminRService.add(userAdminRVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "修改用户管理员关联表")    @ApiOperation(value = "修改用户管理员关联表", notes = "修改用户管理员关联表", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody UserAdminRVO userAdminRVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("修改用户管理员关联表: {}", userAdminRVO);
        return userAdminRService.edit(userAdminRVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "删除用户管理员关联表")    @ApiOperation(value = "删除用户管理员关联表", notes = "删除用户管理员关联表", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody UserAdminRVO userAdminRVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("删除用户管理员关联表: {}", userAdminRVO);
        return userAdminRService.delete(userAdminRVO);
    }
}
